<template>
  <div class="cusha">
    <div class="content_title" v-if="!inline">
      <span @click="showDialogTech" style="cursor: pointer">
        <span class="content_text">粗纱</span>
        <img class="content_img" src="../assets/img/resource/icon/cusha.png" alt="" srcset="" />
      </span>
    </div>
    <div class="cusha_body" :class="{ 'cusha-inline': inline }">
      <div v-for="(item, index) in cushaData.cushaDataRow1Data" :key="index + 'a'" class="cusha_item">
        <div v-if="index == 3">
          <div class="dongli" @click="clickHandleDl('cusha_' + index)">
            <img src="../assets/img/donglis.svg" alt="" srcset="" />
          </div>
        </div>
        <div v-if="index == 13">
          <div class="dongli1" @click="clickHandleDl('cusha_' + index)">
            <img src="../assets/img/dongli.svg" alt="" srcset="" />
          </div>
        </div>
        <div @click="clickHandle(item)">
          <cusha :data="item" :inline="inline"></cusha>
        </div>
      </div>
      <template v-if="inline">
        <div v-for="(item1, index1) in cushaData.cushaDataRow2Data" :key="index1 + 'b'" class="cusha_item cusha_row">
          <div @click="clickHandle(item1)">
            <cusha :data="item1" :inline="inline"></cusha>
          </div>
        </div>
      </template>
    </div>
    <!-- 粗纱弹窗控件 -->
    <cushaDialog ref="cushaDialog"></cushaDialog>
    <!-- 动力柜弹窗控件 -->
    <dongliDialog ref="dongliDialog"></dongliDialog>
    <!-- 粗砂工艺详情 -->
    <cusha-dialog-tech v-if="techShow" ref="cushaDialogTech"></cusha-dialog-tech>
  </div>
</template>

<script>
import dongliDialog from "../views/qcs/components/dialog/dialog_dongli/index";

import cushaDialog from "../views/qcs/components/dialog/dialog_cusha/index";
import cusha from "../views/qcs/components/cusha";
import COMMON from "../utils/common";
import dongLiMenu from "@/assets/data/dongli.json";
import dongliItem from "@/assets/data/dongliItem.json";
export default {
  name: "CuSha",
  props: {
    msg: String,
    // 是否嵌套在弹窗内
    inline: {
      type: Boolean,
      default: false
    }
  },
  components: {
    dongliDialog,
    cusha,
    cushaDialog
  },
  data() {
    return {
      cushaData: {
        // 1-14
        cushaDataRow1Data: [],
        // 15-16
        cushaDataRow2Data: [],
        dongLiMenu: {},
        dongLiItem: {}
      },
      techShow: false
    };
  },
  // 组件相互调用 需在beforeCreate注册
  beforeCreate: function() {
    this.$options.components.cushaDialogTech = require("../views/qcs/components/dialogBig/dialog_cusha_tech/index").default;
  },
  created() {
    this.dongLiMenu = dongLiMenu;
    this.dongLiItem = dongliItem;
  },
  computed: {
    txcsomlGroupState() {
      return this.$store.state.txcsomlGroupState;
    }
  },
  watch: {
    txcsomlGroupState: {
      immediate: true,
      handler(val) {
        this.cushaData.cushaDataRow1Data = COMMON.devSnFilter(val.data, 1, 14);
        this.cushaData.cushaDataRow2Data = COMMON.devSnFilter(val.data, 15, 16);
      }
    }
  },
  methods: {
    closeHandle(type) {
      // 若细砂组件在1.5级弹窗内，当关闭二级弹窗时，需要打开1.5级的轮询
      if (this.inline) {
        // 关闭二级轮询
        this.$EventBus.$emit("clearTypeInterval", type);
        this.$parent.$parent.getTableData();
      } else {
        this.$parent.closeParentHandle();
      }
    },
    clickHandle(item) {
      // 旧粗纱:新粗纱
      let type = item.emp == "0" ? "TXCSOML" : "CUSHA";
      // 若细砂组件在1.5级弹窗内，当打开二级弹窗时，需要关闭1.5级的轮询
      if (this.inline) {
        this.$EventBus.$emit("getInfoByDevSn", type, item.devSn);
        this.$EventBus.$emit("inlineDialog", "close");
      } else {
        this.$parent.getInfoByDevSn(type, item.devSn);
      }
      this.$refs.cushaDialog.showDialog(item);
    },
    clickHandleDl(item) {
      var getInfoQuary = this.dongLiMenu[item];
      var dialogData = this.dongLiItem[item];
      // 若细砂组件在1.5级弹窗内，当打开二级弹窗时，需要关闭1.5级的轮询
      if (this.inline) {
        this.$EventBus.$emit("getInfoByDevSn", "DONGLI", getInfoQuary);
        this.$EventBus.$emit("inlineDialog", "close");
      } else {
        this.$parent.getInfoByDevSn("DONGLI", getInfoQuary);
      }
      this.$refs.dongliDialog.showDialog(dialogData);
    },
    showDialogTech() {
      this.techShow = true;
      this.$nextTick(() => {
        setTimeout(() => {
          // 初始化请求
          // 1.5级轮询
          this.$parent.openInlineDialog("CUSHA", { start: 1, end: 16 });
          this.$refs.cushaDialogTech.showDialog();
        });
      });
    },
    closeDialogTech() {
      this.techShow = false;
      this.$parent.closeParentHandle();
    }
  }
};
</script>

<style scoped></style>
